﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fis.Web.Rules.Service
{
    public class LoginRule : Agile.Engine.Data.DataRule
    {
        public override void ExecuteNonTrans()
        {
            var xml = Agile.Engine.ObjectContext.GetResource("ServiceResource");
            var sql = xml.Merge("login_valid", Paramater);

            var data = Model.QueryTable(System.Data.CommandType.Text, "TUSER", sql);

            ///不存在
            if (data.Rows.Count == 0)
            {
                Status = -1;
                Message = "用户名/密码错误";
            }
            else
            {
                var row = data.Rows[0];
                ///账户禁用
                if (Agile.Engine.Utils.DataUtils.Parse(0, row["FSTATUS"]) < 0)
                {
                    Status = -1;
                    Message = "用户被禁用";
                }
                else
                {
                    Status = 1;
                    Result["data"] = Agile.Engine.Utils.ZipUtils.ZipDataTable(data);
                }
            }
        }
    }
}
